// ml:run = $bin < input
#include <iostream>

using ll = long long;
int const maxn = 1000;
ll a[maxn][maxn];
int n;
int x, y;
ll sum = 0, sum2 = 0;

bool check()
{
    for (int i = 1; i <= n; i++) {
        ll tmp = 0;
        for (int j = 1; j <= n; j++)
            tmp += a[i][j];
        if (tmp != sum) return false;
    }

    for (int j = 1; j <= n; j++) {
        ll tmp = 0;
        for (int i = 1; i <= n; i++)
            tmp += a[i][j];
        if (tmp != sum) return false;
    }
    ll tmp = 0;
    for (int i = 1; i <= n; i++)
        tmp += a[i][i];
    if (tmp != sum) return false;
    tmp = 0;
    for (int i = 1; i <= n; i++)
        tmp += a[i][n - i + 1];
    return tmp == sum;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            std::cin >> a[i][j];
            if (!a[i][j]) {
                x = i; y = j;
            }
        }
    if (n == 1) {
        std::cout << 1 << "\n";
        return 0;
    }
    int row = 1;
    if (x == 1) row = 2;
    for (int i = 1; i <= n; i++) {
        sum += a[row][i];
        sum2 += a[x][i];
    }
    ll ans = sum - sum2;
    if (ans <= 0) {
        std::cout << "-1\n";
        return 0;
    }
    a[x][y] = ans;
    if (check())
        std::cout << ans << "\n";
    else
        std::cout << "-1\n";
}

